package com.gitee.wsl.time.local


import com.gitee.wsl.ext.bitcode.umod
import kotlinx.datetime.DayOfWeek


data class DayOfWeekWithLocale(val dayOfWeek: DayOfWeek, val locale: KlockLocale) : Comparable<DayOfWeekWithLocale> {
    val value: Int get() = (dayOfWeek.ordinal - locale.firstDayOfWeek.ordinal) umod 7
    val ordinal: Int get() = value + 1

    override fun compareTo(other: DayOfWeekWithLocale): Int {
        if (other.locale != this.locale) error("Can't compare two day of weeks with different locales")
        return locale.daysOfWeekComparator.compare(dayOfWeek, other.dayOfWeek)
    }
}

fun DayOfWeek.withLocale(locale: KlockLocale) = locale.localizedDayOfWeek(this)